package cn.iocoder.yudao.module.iot.mq;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.concurrent.TimeUnit;

@Component
public class Producer {

    @Autowired
    private StringRedisTemplate redis;

    private ListOperations<String, String> listRedis;

    @PostConstruct
    private void init(){
        listRedis = redis.opsForList();
    }

    public void publishMessage(String channel,String message){
        listRedis.leftPush(channel, message);
        redis.expire(channel,30,TimeUnit.MINUTES);
    }

}